import { delay } from './index';
import { host } from './host';
import request from './request';

request.setConfig({
  // baseUrl: '/api',
  baseUrl: host,
  loadingText: '努力加载中~',
  loadingTime: 800,
  loadingMask: true,
  originalData: true,
  timeout:8000,
  header: {
    'content-type': 'application/json;charset=UTF-8',
  },
});

request.interceptor.request = (config) => {
  return config;
};

let message = null;
request.interceptor.response = (response) => {
  if (response.data.code != '200' && !message) {
    message = response.data.msg;
    uni.showToast({
      icon: 'none',
      title: message,
      success: async () => {
        await delay(1500);
        message = null;
      },
    });
  }
  return response.data;
};

export default request;
